<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
const info = ref({})

onMounted(async () => {
  const token = localStorage.getItem('token');
  console.log(token);
  
try {
    const res = await axios.get('http://localhost:8080/emp/PersonalInformation', {
      headers: {
        'token': localStorage.getItem('token')
      },
      params: {
        employeeId: localStorage.getItem('employeeId')
      }
    })
    console.log(res)
    // 假设后端返回的数据在res.data.data
    if (res.data.code === 200) {
      info.value = res.data.data || {}
    } else {
      console.error('获取个人信息失败', res.data.message)
    }
  } catch (e) {
    // 错误处理
    console.error('获取个人信息失败', e)
  }
})
</script>

<template>
  <div class="profile-container">
    <!-- 左侧信息 -->
    <div class="profile-sidebar">
      <img :src="info.photo" alt="员工照片" class="profile-photo-large" v-if="info.photo">
      <div class="profile-name">{{ info.name }}</div>
      <div class="profile-last-login">
        上次登录：{{ info.lastLoginTime ? info.lastLoginTime.replace('T', ' ').slice(0, 19) : '' }}
      </div>
    </div>
    <!-- 右侧卡片信息 -->
    <div class="profile-main">
      <!-- 基础信息卡片 -->
      <div class="profile-card-block">
        <div class="card-header">
          <span>📋 基础信息</span>
        </div>
        <div class="card-content two-cols">
          <div class="item"><span class="label">员工编号：</span>{{ info.employeeId }}</div>
          <div class="item"><span class="label">姓名：</span>{{ info.name }}</div>
          <div class="item"><span class="label">性别：</span>{{ info.gender }}</div>
          <div class="item"><span class="label">身份证号：</span>{{ info.idCard }}</div>
          <div class="item"><span class="label">出生日期：</span>{{ info.birthDate ? info.birthDate.slice(0,10) : '' }}</div>
        </div>
      </div>
      <!-- 联系方式卡片 -->
      <div class="profile-card-block">
        <div class="card-header">
          <span>📞 联系方式</span>
        </div>
        <div class="card-content two-cols">
          <div class="item"><span class="label">手机号码：</span>{{ info.phone }}</div>
          <div class="item"><span class="label">电子邮箱：</span>{{ info.email }}</div>
        </div>
      </div>
      <!-- 职位信息卡片 -->
      <div class="profile-card-block">
        <div class="card-header">
          <span>ℹ️ 职位信息</span>
        </div>
        <div class="card-content two-cols">
          <div class="item"><span class="label">所属部门：</span>{{ info.department?.departmentName || '' }}</div>
          <div class="item"><span class="label">岗位名称：</span>{{ info.position }}</div>
          <div class="item"><span class="label">入职日期：</span>{{ info.hireDate ? info.hireDate.slice(0,10) : '' }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.profile-container {
  display: flex;
  gap: 40px;
  max-width: 1100px;
  margin: 40px auto;
}
.profile-sidebar {
  width: 260px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  padding: 32px 0 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.profile-photo-large {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #f0f0f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.profile-name {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 18px 0 6px 0;
}
.profile-vip {
  color: #f7b500;
  font-size: 1.1rem;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.vip-icon {
  font-size: 1.2rem;
}
.profile-last-login {
  color: #888;
  font-size: 0.98rem;
  margin-top: 8px;
}
.profile-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.profile-card-block {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  padding: 22px 28px 18px 28px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.13rem;
  font-weight: bold;
  margin-bottom: 16px;
}
.edit-btn {
  background: #f5f7fa;
  border: none;
  color: #409eff;
  border-radius: 6px;
  padding: 4px 16px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.edit-btn:hover {
  background: #e6f0fa;
}
.card-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.two-cols {
  flex-direction: row;
  flex-wrap: wrap;
}
.two-cols .item {
  width: 48%;
  margin-bottom: 10px;
  font-size: 1.08rem;
  display: flex;
  align-items: center;
}
.label {
  color: #888;
  min-width: 90px;
  display: inline-block;
}
</style>